<?php
class koudai_adminModel extends model{
	public $base;
	public $oc_where;
	public function __construct(&$base){
		parent::__construct($base);
		$this->base=$base;
		$this->table="koudai_admin";
	}
	
	public function typelist(){
		return array(
			1=>"管理员",
			2=>"签单对账",
		);
	}
	
	public function addMoney($option){
		$adminid=$option['adminid'];
		$row=$this->selectRow("adminid=".$adminid);
		if(empty($row)) return false;
		$data=array();
		if(isset($option['money'])){
			$data['money']=$row['money']+$option['money'];
			
		}
		
		if(isset($option['income'])){
			$data['income']=$row['income']+$option['income'];
		}
		
		if(isset($option['balance'])){
			$data['balance']=$row['balance']+$option['balance'];
		}
		$this->update($data,"adminid=".$adminid);
		 
		$logdata=array(
				"dateline"=>time(),
				"adminid"=>$adminid,
				"type_id"=>1,
				"siteid"=>SITEID,
				"shopid"=>$option['shopid']				 
		);
		if(isset($option['balance'])){
			$logdata['k']='balance';
			$logdata['money']=$option['balance'];
			$logdata['content']=str_replace("[money]",$option['balance'],$option['content']) ." 原来".$row['balance']."元，现在".$data['balance']."元";
			M("koudai_admin_pay_log")->insert($logdata);
		}
		
		if(isset($option['income'])){
			$logdata['k']='income';
			$logdata['money']=$option['income'];
			$logdata['content']=str_replace("[money]",$option['income'],$option['content'])." 原来".$row['income']."元，现在".$data['income']."元";
			M("koudai_admin_pay_log")->insert($logdata);
		}
		
		if(isset($option['money'])){
			$logdata['k']='money';
			$logdata['money']=$option['money'];
			$logdata['content']=str_replace("[money]",$option['money'],$option['content'])." 原来".$row['money']."元，现在".$data['money']."元";
			M("koudai_admin_pay_log")->insert($logdata);
		}
		
	}
	
	
	 
	 
	
	
	
	
}

?>